package com.iworkh.spring.beans.factory;

import com.iworkh.spring.beans.bean.entity.Car;

import java.util.HashMap;
import java.util.Map;

/**
 * 静态工厂方法
 *
 * @author: iworkh-沐雨云楼
 * @date: 2019-12-18
 */
public class StaticCarBeanFactory {

    private static Map<String, Car> carMap = new HashMap<>();

    static {
        carMap.put("zhangsan", new Car("张三", "宝马"));
        carMap.put("lisi", new Car("李四", "奥迪"));
        carMap.put("wangwu", new Car("王五", "奔驰"));
    }

    public static Car getCar(String name) {
        return carMap.getOrDefault(name, new Car("无名氏", "自行车一辆"));
    }
}
